package com.lin;

import java.lang.management.MonitorInfo;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Solution738 {

    public static void main(String[] args) {
        int ans = monotoneIncreasingDigits(332);
        System.out.println(ans);
    }
    public static int monotoneIncreasingDigits(int N) {

        char[] chars = Integer.toString(N).toCharArray();
        for (int i = chars.length-2;i>=0;i--){
            if(chars[i]>chars[i+1]){
                chars[i]--;
                for(int j = i+1;j<chars.length;j++){
                    chars[j] = '9';
                }
            }
        }
        int ans = 0;
        for (int i=0;i<chars.length;i++){
            ans = ans*10+(chars[i]-'0');
        }
        return ans;
    }


}
